﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Interfaces;
using System.Xml.Serialization;
using System.IO;
using System.MessagingCE;

namespace Receiver
{
    public partial class Form1 : Form
    {
        private MessageQueue testQ;

        public Form1()
        {
            InitializeComponent();
            testQ = new MessageQueue(true, "NewSignalEvent");
            testQ.DataOnQueueChanged += new EventHandler(testQ_DataOnQueueChanged);

        }

        void testQ_DataOnQueueChanged(object sender, EventArgs e)
        {
            this.Invoke(new EventHandler(this.OnNewSignalEvent));
        }

        private void OnNewSignalEvent(object sender, EventArgs e)
        {
            Message msg = new Message();
            ReadWriteResult rwr = testQ.Receive(msg);
            if (rwr == ReadWriteResult.OK)
            {
                textBox1.Text += new ASCIIEncoding().GetString(msg.MessageBytes, 0, msg.MessageBytes.Length) + "\r\n";
            }
        }
    }
}